package vip.xiaomaoxiaoke.util;

import com.google.common.base.Supplier;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class BeanUtils {

    public static <T,S> List<T> copyListProperties(List<S> sources, Supplier<T> supplier) {
        if (sources == null) return new ArrayList<>();
        List<T> targets = sources.stream().map(source -> {
            T target = supplier.get();
            org.springframework.beans.BeanUtils.copyProperties(source, target);
            return target;
        }).collect(Collectors.toList());
        return targets;
    }

    public static void copyProperties(Object source,Object target) {
        org.springframework.beans.BeanUtils.copyProperties(source, target);
    }

    public static <T> T copyProperties(Object source, Supplier<T> supplier) {
        T t = supplier.get();
        org.springframework.beans.BeanUtils.copyProperties(source, t);
        return t;
    }


}
